package com.gxa.zhonglong.controller;

import com.gxa.zhonglong.common.JsonResult;
import com.gxa.zhonglong.exception.BusinessException;
import com.gxa.zhonglong.pojo.GoodsPrice;
import com.gxa.zhonglong.pojo.LaborCharges;
import com.gxa.zhonglong.service.GoodsPriceService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

/**
 * @author NITRO
 */

@Api
@CrossOrigin
@RestController
@RequestMapping("/goodsPrice")
public class GoodsPriceController {


    @Autowired
    private GoodsPriceService goodsPriceService;

    @ApiOperation(value = "添加商品价格")
    @PostMapping("/addGoodsPrice")
    public Map addGoodsPrice( GoodsPrice goodsPrice) throws BusinessException {
        System.out.println("goodsPrice:"+goodsPrice);
        JsonResult jsonResult=new JsonResult();
        goodsPriceService.addGoodsPrice(goodsPrice);
        jsonResult.setCode("1");
        return jsonResult.getDataMap();
    }


    @PostMapping("/deleteGoodsPrice")
    @ApiOperation("删除商品价格")
    public Map<String,Object> deleteGoodsPrice(@RequestBody Map<String,List<Long>> ids) throws BusinessException {
        goodsPriceService.deleteGoodsPrice(ids.get("ids"));
        JsonResult jsonResult=new JsonResult();
        jsonResult.setCode("1");
        return jsonResult.getDataMap();
    }

    @ApiOperation(value = "修改商品价格")
    @PostMapping("/updateGoodsPrice")
    public Map updateGoodsPrice( GoodsPrice goodsPrice) throws BusinessException {
        JsonResult jsonResult = new JsonResult();
        Boolean aBoolean = goodsPriceService.updateGoodsPrice(goodsPrice);
        jsonResult.setCode("1");
        return jsonResult.getDataMap();
    }

    @ApiOperation(value = "查询商品价格")
    @PostMapping("/getGoodsPriceList")

    public Map getGoodsPriceList(){


        List<GoodsPrice> goodsPriceList = goodsPriceService.getGoodsPriceList();
        JsonResult jsonResult = new JsonResult();
        jsonResult.setData(goodsPriceList);
        jsonResult.setCode("1");
        return jsonResult.getDataMap();
    }
}
